// 判断token不存在跳转到登录页
if (!sessionStorage.getItem('token')) {
    window.location.href = './login.html';
}

// 首页名称|头像
window.userinfo = function () {
    getUserInfoAPI({}, res => {
        let {nickname, user_pic, username} = res.data.data;
        if (nickname == null) {
            $(".username").html(username);
        }else {
            $(".username").html(nickname);
        }
        if (user_pic == null) { // 字母头像
            let firstUname = username[0].toUpperCase();
            $('.avatar').html(firstUname).css('display', 'inline-block');
        } else {
            $(".layui-nav-img").attr('src', user_pic).stop().show();
        }
    })
}
userinfo();

// 退出
$("#logout").on('click', function () {
    layer.confirm('确定要退出吗?', {
        icon: 3,
        title: '提示',
        move: false
    }, function (index) {
        window.parent.sessionStorage.removeItem('token');
        layer.msg('退出成功', {
            icon: 6,
            time: 200,
            end: function () {
                window.parent.location.href = '/login.html';
            }
        })
        layer.close(index);
    });

})
